using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

[CustomPropertyDrawer(typeof(SpineParamterStateAttribute))]
public class SpineParamterStateAttributeDrawer : PropertyDrawer
{
    public override VisualElement CreatePropertyGUI(SerializedProperty property)
    {
        var choices = SpineTouchConfigSOEditor.ConfigSO.definitions.ConvertAll(d => d.Name);
        var selectIndex = choices.FindIndex(c => c == property.stringValue);
        var pop = new PopupField<string>(property.name, choices, selectIndex);
        pop.RegisterValueChangedCallback(evt =>
        {
            property.stringValue = evt.newValue;
            property.serializedObject.ApplyModifiedProperties();
        });
        // 在鼠标按下时（打开下拉前）更新选项
        pop.RegisterCallback<MouseEnterEvent>(evt =>
        {
            //Debug.Log("鼠标点击");
            var newChoices = SpineTouchConfigSOEditor.ConfigSO.definitions.ConvertAll(d => d.Name);
            var newSelectIndex = newChoices.FindIndex(c => c == property.stringValue);
            pop.choices = newChoices;
            pop.value = newSelectIndex >= 0 ? newChoices[newSelectIndex] : string.Empty;
        });

        return pop;
    }
}